#ifndef SRC_BASE_SYSTEMDETECTION_H_
#define SRC_BASE_SYSTEMDETECTION_H_

/*
   The operating system, must be one of: (OS_x)

     DARWIN   - Any Darwin system (OS X, iOS, watchOS, tvOS)
     OSX      - OS X
     IOS      - iOS
     WATCHOS  - watchOS
     TVOS     - tvOS
     MSDOS    - MS-DOS and Windows
     OS2      - OS/2
     OS2EMX   - XFree86 on OS/2 (not PM)
     WIN32    - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008)
     WINCE    - WinCE (Windows CE 5.0)
     WINRT    - WinRT (Windows 8 Runtime)
     CYGWIN   - Cygwin
     SOLARIS  - Sun Solaris
     HPUX     - HP-UX
     ULTRIX   - DEC Ultrix
     LINUX    - Linux [has variants]
     FREEBSD  - FreeBSD [has variants]
     NETBSD   - NetBSD
     OPENBSD  - OpenBSD
     BSDI     - BSD/OS
     IRIX     - SGI Irix
     OSF      - HP Tru64 UNIX
     SCO      - SCO OpenServer 5
     UNIXWARE - UnixWare 7, Open UNIX 8
     AIX      - AIX
     HURD     - GNU Hurd
     DGUX     - DG/UX
     RELIANT  - Reliant UNIX
     DYNIX    - DYNIX/ptx
     QNX      - QNX [has variants]
     QNX6     - QNX RTP 6.1
     LYNX     - LynxOS
     BSD4     - Any BSD 4.4 system
     UNIX     - Any UNIX BSD/SYSV system
     ANDROID  - Android platform
     HAIKU    - Haiku

   The following operating systems have variants:
     LINUX    - both OS_LINUX and OS_ANDROID are defined when building for Android
              - only OS_LINUX is defined if building for other Linux systems
     FREEBSD  - OS_FREEBSD is defined only when building for FreeBSD with a BSD userland
              - OS_FREEBSD_KERNEL is always defined on FreeBSD, even if the userland is from GNU
*/

#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
# include <TargetConditionals.h>
# if defined(TARGET_OS_MAC) && TARGET_OS_MAC
#   define OS_DARWIN
#   define OS_BSD4
#   ifdef __LP64__
#     define OS_DARWIN64
#   else
#     define OS_DARWIN32
#   endif
#   if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
#     if defined(TARGET_OS_TV) && TARGET_OS_TV
#       define OS_TVOS
#     elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
#       define OS_WATCHOS
#     else
#       // TARGET_OS_IOS is only available in newer SDKs,
#       // so assume any other iOS-based platform is iOS for now
#       define OS_IOS
#     endif
#   else
#     // there is no "real" OS X define (rdar://22640089),
#     // assume any non iOS-based platform is OS X for now
#     define OS_OSX
#   endif
# else
#   error "Not support this Apple platform"
# endif
#elif defined(__ANDROID__) || defined(ANDROID)
# define OS_ANDROID
# define OS_LINUX
#elif defined(__CYGWIN__)
# define OS_CYGWIN
#elif !defined(SAG_COM) && (!defined(WINAPI_FAMILY) || WINAPI_FAMILY==WINAPI_FAMILY_DESKTOP_APP) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
# define OS_WIN32
# define OS_WIN64
#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
# if defined(WINCE) || defined(_WIN32_WCE)
#   define OS_WINCE
# elif defined(WINAPI_FAMILY)
#   ifndef WINAPI_FAMILY_PC_APP
#     define WINAPI_FAMILY_PC_APP WINAPI_FAMILY_APP
#   endif
#   if defined(WINAPI_FAMILY_PHONE_APP) && WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP
#     define OS_WINPHONE
#     define OS_WINRT
#   elif WINAPI_FAMILY==WINAPI_FAMILY_PC_APP
#     define OS_WINRT
#   else
#     define OS_WIN32
#   endif
# else
#   define OS_WIN32
# endif
#elif defined(__sun) || defined(sun)
# define OS_SOLARIS
#elif defined(hpux) || defined(__hpux)
# define OS_HPUX
#elif defined(__ultrix) || defined(ultrix)
# define OS_ULTRIX
#elif defined(sinix)
# define OS_RELIANT
#elif defined(OS_NACL)
# define OS_NACL
#elif defined(__linux__) || defined(__linux)
# define OS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
# ifndef __FreeBSD_kernel__
#   define OS_FREEBSD
# endif
# define OS_FREEBSD_KERNEL
# define OS_BSD4
#elif defined(__NetBSD__)
# define OS_NETBSD
# define OS_BSD4
#elif defined(__OpenBSD__)
# define OS_OPENBSD
# define OS_BSD4
#elif defined(__bsdi__)
# define OS_BSDI
# define OS_BSD4
#elif defined(__sgi)
# define OS_IRIX
#elif defined(__osf__)
# define OS_OSF
#elif defined(_AIX)
# define OS_AIX
#elif defined(__Lynx__)
# define OS_LYNX
#elif defined(__GNU__)
# define OS_HURD
#elif defined(__DGUX__)
# define OS_DGUX
#elif defined(__QNXNTO__)
# define OS_QNX
#elif defined(_SEQUENT_)
# define OS_DYNIX
#elif defined(_SCO_DS) /* SCO OpenServer 5 + GCC */
# define OS_SCO
#elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */
# define OS_UNIXWARE
#elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */
# define OS_UNIXWARE
#elif defined(__INTEGRITY)
# define OS_INTEGRITY
#elif defined(VXWORKS) /* there is no "real" VxWorks define - this has to be set in the mkspec! */
# define OS_VXWORKS
#elif defined(__HAIKU__)
# define OS_HAIKU
#elif defined(__MAKEDEPEND__)
#else
# error "Not support this OS"
#endif

#if defined(OS_WIN32) || defined(OS_WIN64) || defined(OS_WINCE) || defined(OS_WINRT)
# define OS_WIN
#endif

#if defined(OS_WIN)
# undef OS_UNIX
#elif !defined(OS_UNIX)
# define OS_UNIX
#endif

// Compatibility synonyms
#ifdef OS_DARWIN
# define OS_MAC
#endif
#ifdef OS_DARWIN32
# define OS_MAC32
#endif
#ifdef OS_DARWIN64
# define OS_MAC64
#endif
#ifdef OS_OSX
# define OS_MACX
#endif

#endif // SRC_BASE_SYSTEMDETECTION_H_
